#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);

    int t;
    string s;

    cin>>t;
    while(t--) {
        cin>>s;
        char m = CHAR_MAX;
        int id = 0;
        for(int i=0;i<s.size();i++) {
            char ch = s[i];
            if (ch < m) {
                m = ch;
                id = i;
            }
        }

        s.erase(id, 1);
        cout << m << ' ' << s << endl;
    }
    return 0;
}